package pubsub;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;

import topics.Topic;
import topics.TopicSpace;
import topics.TopicSpaceSet;
import topics.expression.TopicExpression;
import topics.expression.TopicExpressionException;
import topics.expression.impl.TopicExpressionImpl;
import topics.impl.TopicSpaceSetImpl;
import topics.util.TopicSpaceParser;
import topics.v2004_06.TopicsConstants;
import util.xml.NamespaceContextImpl;

public class TestMain {
	
	private static TopicSpace topicspace = null;
	
	public static void main(String[] args) {
		File file = new File("topics.xml");
		InputStream inStream = null;
		try {
			inStream = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		TopicSpaceParser parser = new TopicSpaceParser();
		
		topicspace = parser.parse(inStream);
		
		TopicSpaceSet topicspaceset = new TopicSpaceSetImpl(true);
		topicspaceset.addTopicSpace(topicspace);
		TopicExpression expression = null;
		//<wsnt:TopicExpression Dialect=\"http://docs.oasis-open.org/wsn/t-1/TopicExpression/Simple\">tns:t1</wsnt:TopicExpression>
		try {
			expression = new TopicExpressionImpl((Object)"tns:t1/t3",(Object)new NamespaceContextImpl(), new URI(TopicsConstants.TOPIC_EXPR_DIALECT_CONCRETE));
		} catch (URISyntaxException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Topic[] topics = null;
		try {
			topics = topicspaceset.evaluateTopicExpression(expression);
		} catch (TopicExpressionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(topics[0].getName());
		
	}
}
